package com.yc.cinema.mapper;

import org.apache.ibatis.annotations.*;
import org.example.entity.Movie;

import java.util.List;

public interface MovieMapper {

    @Select("<script>" +
            "select * from movie\n" +
            "        <where>\n" +
            "            <if test=\"name != null\">\n" +
            "                and name = #{name}\n" +
            "            </if>\n" +
            "            <if test=\"releaseTime != null\">\n" +
            "                and release_time = #{releaseTime}\n" +
            "            </if>\n" +
            "            <if test=\"foreignName != null\">\n" +
            "                and foreign_name = #{foreignName}\n" +
            "            </if>\n" +
            "        </where>" +
            "</script>")
    List<Movie> selectMovies(Movie movie);
    void updateNotNull(Movie movie);

    @Update("        update movie\n" +
            "        set name = #{name},release_time = #{releaseTime},foreign_name = #{foreignName}\n" +
            "        where id = #{id}")
    void updateAll(Movie movie);

    @Select("select * from movie where id=#{id}")
    Movie selectById(int id);

    List<Movie> selectByLanguages(@Param("languages") List<String> abc);

    void insertList(@Param("movies") List<Movie> movies);
    @Insert("insert into movie\n" +
            "        (id,name,duration,release_time, foreign_name) values\n" +
            "        (default, #{name},#{duration},now(), #{foreignName})")
    @Options(useGeneratedKeys = true,keyProperty = "id", keyColumn = "id")
    void insert(Movie movie);

    List<Movie> selectLikeName(@Param("name") String name,
                               @Param("role") String role,
                               @Param("order") String order);
}
